<!-- 数字组件 -->
<template>
  <input @input="handleChange"  class="m-number" ref="input">
</template>

<script>

    let numReg = /^[1-9][0-9]*$/

  export default {
      props:['value'],
    data(){
      return {
          currentValue:this.value
      }
    },
      watch:{
          currentValue: function (val) {
              this.$refs.input.value = val
          },
          value:function (val) {
              this.updataValue(val);
          }
      },
      mounted() {
          this.updataValue(this.value);
      },
    methods: {
        updataValue: function (val) {
            this.currentValue = val;
        },
        handleChange: function (e) {
            let {target} = e
            let {value} = target

            if(value === ''){
                return
            }

            if(numReg.test(value)){
                target.numPre = value
            } else {
                // target.value = ((value.length == 1) ? '' : (target.numPre || ''))
                target.value = ((value.length == 1) ? '' : (target.numPre || ''))
            }
            this.$emit('input',target.value);
            //this.currentValue = target.value
        }
    }
  }
</script>

<style lang="scss" scoped>
  @import "~common/scss/variable";



</style>
